import time

from pages.business.BusinessPage import BusinessPage
from utils.config import host_port


# 页面元素定位层
class DeckTypePage(BusinessPage):
    def __init__(self):
        BusinessPage.__init__(self)
        time.sleep(3)
        self.driver.get(f'https://{host_port}/decklist-decktype')

    # 新增按钮
    def get_add_type_element(self):
        return self.driver.find_element_by_xpath(
            '//*[@id="pane-decklist-decktype"]/div/div/div/form/div[2]/div/button[2]')

    # 输入框
    def get_name_element(self):
        return self.driver.find_element_by_xpath(
            '//*[@id="pane-decklist-decktype"]/div/div/div/div[3]/div/div[2]/form/div/div/div/input')

    # 确定按钮
    def get_confirm_btn_element(self):
        return self.driver.find_element_by_xpath(
            '//*[@id="pane-decklist-decktype"]/div/div/div/div[3]/div/div[3]/span/button[2]/span')


# 操作层
class DeckTypeHandle(DeckTypePage):
    def __init__(self):
        DeckTypePage.__init__(self)

    # 点击新增按钮
    def click_add(self):
        self.get_add_type_element().click()

    # 输入框
    def send_name_input(self, name):
        self.get_name_element().send_keys(name)

    # 点击确认按钮
    def click_confirm_btn(self):
        self.get_confirm_btn_element().click()


# 业务层
class DeckTypeBusiness(DeckTypeHandle):
    def __init__(self):
        DeckTypeHandle.__init__(self)

    def addDeckType(self, name):
        self.click_add()
        time.sleep(3)
        self.send_name_input(name)
        self.click_confirm_btn()
        return "新增成功"

# class DeckTypePage:
#     def __init__(self):
#         self.driver = GetFact.getDriver()
#         time.sleep(3)
#         self.driver.get(f'https://{host_port}/decklist-decktype')
#
#     def addDeckType(self, name):
#         # 点击了新增
#         self.driver.find_element_by_xpath(
#             '//*[@id="pane-decklist-decktype"]/div/div/div/form/div[2]/div/button[2]').click()
#
#         time.sleep(3)
#
#         self.driver.find_element_by_xpath(
#             '//*[@id="pane-decklist-decktype"]/div/div/div/div[3]/div/div[2]/form/div/div/div/input').send_keys(name)
#
#         time.sleep(3)
#
#         # 点确定
#         self.driver.find_element_by_xpath(
#             '//*[@id="pane-decklist-decktype"]/div/div/div/div[3]/div/div[3]/span/button[2]/span').click()
#
#         time.sleep(3)
#
#         return "新增成功"
